package com.tensquare.friend.dao;

import com.tensquare.friend.pojo.Friend;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @author zzb
 * @version 1.0
 * @create 2020/12/24 10:51
 */
public interface FriendDao extends JpaRepository<Friend,String> {
    //根据用户id和好友id查询是否有记录
    @Query(nativeQuery = true,value = "select count(*) from tb_friend where userid=?1 and friendid=?2")
    int selectCount(String id, String friendid);

    //修改islike的值为1，双方互相有好友
    @Modifying
    @Query(nativeQuery = true,value = "update tb_friend set islike=?3 where userid=?1 and friendid=?2")
    void updateIsLike(String id, String friendid, String islike);

    //从好友表删除记录
    @Modifying
    @Query(nativeQuery = true,value = "delete from tb_friend where userid=?1 and friendid=?2")
    void deleteUser(String userId, String friendid);
}
